<template>
	<view class="content">

		<scroll-view class="scroll" scroll-y>
			<view class="scroll-content">
				<view class="introduce-section">
					<text class="title">{{article_title}}</text>
					<view class="introduce">
						<text class="author">{{artitle_author}}</text>
						<text class="time">{{artitle_time}}</text>
					</view>
					
					<!-- 文章详情 -->
					<view class="article-content">
						<view class="parse-con">
							<u-parse :content="article_detail.content" @navigate="navigate"></u-parse>
						</view>

						<view v-if="article_detail.fields.source" class="article-source">
							文章来自：{{article_detail.fields.source}}
						</view>
					</view>
					<!-- /文章详情 -->
					
					<view class="actions" v-show="false">
						  
					</view>
				</view>

				<view class="container" v-show="loading === false">
					<!-- 推荐 -->
					<view class="s-header">
						<text class="tit">相关推荐</text>
					</view>
					<view class="rec-section" v-for="item in newsList" :key="item.id" @click="navToDetails(item)">
						<view class="rec-item">
							<view class="left">
								<text class="title">{{item.title}}</text>
								<view class="bot">
									<text class="author">{{item.user_name}}</text>
									<text class="time">{{item.add_time}}</text>
								</view>
							</view>
							<view class="right" v-if="item.img_url">
								<image class="img" :src="item.img_url" mode="aspectFill"></image>
							</view>
						</view>
					</view>

					 
				 
					 
				</view>
				<!-- 加载图标 -->
				<mixLoading class="mix-loading" v-if="loading"></mixLoading>
			</view>
		</scroll-view>
 <view class="cu-bar bg-blue light solid-bottom ">
 	<view class="text-bold">
 		 
 	</view>
 	<view class="action">
 		<button class="cu-btn bg-orange shadow" @click="navToLanmu" >{{article_detail.category_name}}更多文章 >></button>
 	</view>
 </view>
	</view>
</template>

<script>
	import {
		friendlyDate
	} from '@/common/util.js';
	import uParse from "@/components/feng-parse/parse.vue"
	import mixLoading from '@/components/mix-loading/mix-loading';
	const FAIL_CONTENT = '<p>数据加载中</p>';
	export default {
		components: {
			mixLoading,
			uParse
		},
		data() {
			return {
				loading: true, 
				newsList: [], 
				article_detail: {},
				article_title: '',
				artitle_author: '',
				artitle_time: '',
				dianzan:860,
				dianno:0,
				id: 0,
			}
		},
		onShareAppMessage() {
			return {
				title: this.article_detail.title+getApp().globalData.title,
				content: this.article_detail.title,
				path: '/pages/detail/detail?query=' + this.id,
				imageUrl: getApp().globalData.zyiz_share_img
			}
		},
		onLoad(options) {
			try {
				 
				console.log('入参：' + options.query);
				this.id = options.query;
			} catch (error) {
				console.log('异常来了');

			}

			this.getDetail();

			this.loadNewsList();
			 
		},
		onShow: function() {
			console.log('onShow里：');
			console.log('id=' + this.id);

			// #ifdef  MP-BAIDU 
			//百度引导关注
			swan.showFavoriteGuide({
			    type: 'bar',
			    content:'关注找一找教程网小程序'
			});
			//web化 seo
			var zyizurl = getApp().globalData.zyiz_domain + '/api/Zyiz/Detail/' + this.id;
			uni.request({
				url: zyizurl,
				success: (result) => {

					if (result.statusCode == 200) {
						console.log("详情结果2：");
						console.log(result);
						var article_d = result.data.data;
						var keyw = article_d.category_name+ ','+article_d.tags  ;
						if (article_d.seo_keywords) {
							keyw =  article_d.category_name + ','+article_d.tags + ',' + article_d.seo_keywords;
						}
						var zhaiyao = getApp().globalData.description;
						if (article_d.zhaiyao) {
							zhaiyao = article_d.zhaiyao;
						}
						var img_url = getApp().globalData.zyiz_image;
						if (article_d.img_url) {
							img_url = article_d.img_url;
						}
						var title = article_d.title + '-' + article_d.category_name+'-'+getApp().globalData.title;
						swan.setPageInfo({
							title: title,
							keywords: keyw,
							description: zhaiyao,
							articleTitle: title,
							releaseDate: article_d.add_time,
							image: img_url,
							video: ''
						});


					}

				}
			});


			// #endif

		},
		methods: {
			//文章详情
			getDetail() {

				var zyizurl = getApp().globalData.zyiz_domain + '/api/Zyiz/Detail/' + this.id;
				uni.request({
					url: zyizurl,
					success: (result) => {

						if (result.statusCode == 200) {
							console.log("详情结果：");
							console.log(result);

							this.article_detail = result.data.data;
							this.article_title = result.data.data.title;
							this.artitle_author = result.data.data.fields.author;
							this.artitle_time = friendlyDate(new Date(result.data.data.add_time.replace(/\-/g,'/')).getTime());
							
							uni.setNavigationBarTitle({
							    title: result.data.data.title+'-找一找教程网'
							});
							
						}

					}
				});

			},
			//获取推荐列表
			async loadNewsList() {
				  
				var zyizurl = getApp().globalData.zyiz_domain + '/api/Zyiz/RelationList/' + this.id;
				uni.request({
					url: zyizurl,
					success: (result) => {
				
						if (result.statusCode == 200) {
							console.log("关联文章结果：");
							console.log(result);
				
							let list = result.data.data; 
							list.forEach(item => {
								item.add_time=friendlyDate(new Date(item.add_time.replace(/\-/g,'/')).getTime()),
								this.newsList.push(item);
							})
							
							this.loading = false;
						}
				
					}
				});
				
				
				
			},
			navToDetails(item) {
							 
			console.log('跳转之前');
			console.log(item.id);
							uni.navigateTo({
							 
								url: '/pages/detail/detail?query=' +item.id
							})
						},
						//去栏目页
			navToLanmu() {
				if(this.article_detail.category_id==292)
				{
					uni.switchTab({
						url:'/pages/zixun/zixun'
					})
				}
				else
				{
					uni.navigateTo({
						url:'/pages/list/list?query='+this.article_detail.category_id
					})
				}
				
			 
			},
			 
		}
	}
</script>

<style lang="scss">
	@import url("../../components/feng-parse/parse.css");

	page {
		height: 100%;
	}

	.content {
		display: flex;
		flex-direction: column;
		height: 100%;
		background: #fff;
	}

	.video-wrapper {
		height: 422upx;

		.video {
			width: 100%;
			height: 100%;
		}
	}

	.scroll {
		flex: 1;
		position: relative;
		background-color: #f8f8f8;
		height: 0;
	}

	.scroll-content {
		display: flex;
		flex-direction: column;
	}

	/* 简介 */
	.introduce-section {
		display: flex;
		flex-direction: column;
		padding: 20upx 30upx;
		background: #fff;
		line-height: 1.5;

		.title {
			font-size: 36upx;
			color: #303133;
			margin-bottom: 16upx;
		}

		.introduce {
			display: flex;
			font-size: 26upx;
			color: #909399;
			
			text {
				 
				margin-right: 16upx;
			}
		}
		.article-content {
			font-size: 30upx;
			padding-top:20px;
			margin-bottom: 30upx;
			overflow: hidden;
		}
		.article-source {
			padding: 10upx;
			color: #AAAAAA;
			font-size: 24upx;
		}
	}


	/* 点赞等操作 */
	.actions {
		display: flex;
		justify-content: space-around;
		align-items: center;
		line-height: 1.3;
		padding: 10upx 40upx 20upx;

		.action-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			font-size: 24upx;
			color: #999;
		}

		.yticon {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60upx;
			height: 60upx;
			font-size: 52upx;

			&.reverse {
				position: relative;
				top: 6upx;
				transform: scaleY(-1);
			}

			&.active {
				color: #ec706b;
			}
		}

		.icon-fenxiang2 {
			font-weight: bold;
			font-size: 36upx;
		}

		.icon-shoucang {
			font-size: 44upx;
		}
	}

	.s-header {
		padding: 20upx 30upx;
		font-size: 30upx;
		color: #303133;
		background: #fff;
		margin-top: 16upx;

		&:before {
			content: '';
			width: 0;
			height: 40upx;
			margin-right: 24upx;
			border-left: 6upx solid #ec706b;
		}
	}

	/* 推荐列表 */
	.rec-section {
		background-color: #fff;

		.rec-item {
			display: flex;
			padding: 20upx 30upx;
			position: relative;

			&:after {
				content: '';
				position: absolute;
				left: 30upx;
				right: 0;
				bottom: 0;
				height: 0;
				border-bottom: 1px solid #eee;
				transform: scaleY(50%);
			}
		}

		.left {
			flex: 1;
			padding-right: 10upx;
			overflow: hidden;
			position: relative;
			padding-bottom: 52upx;

			.title {
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
				font-size: 32upx;
				color: #303133;
				line-height: 44upx;
			}

			.bot {
				position: absolute;
				left: 0;
				bottom: 4upx;
				font-size: 26upx;
				color: #909399;
			}

			.time {
				margin-left: 20upx;
			}
		}

		.right {
			width: 220upx;
			height: 140upx;
			flex-shrink: 0;
			position: relative;

			.img {
				width: 100%;
				height: 100%;
			}

		}
	}

	/* 评论 */
	.evalution {
		display: flex;
		flex-direction: column;
		background: #fff;
		padding: 20upx 0;
	}

	.eva-item {
		display: flex;
		padding: 20upx 30upx;
		position: relative;

		image {
			width: 60upx;
			height: 60upx;
			border-radius: 50px;
			flex-shrink: 0;
			margin-right: 24upx;
		}

		&:after {
			content: '';
			position: absolute;
			left: 30upx;
			bottom: 0;
			right: 0;
			height: 0;
			border-bottom: 1px solid #eee;
			transform: translateY(50%);
		}

		&:last-child:after {
			border: 0;
		}
	}

	.eva-right {
		display: flex;
		flex-direction: column;
		flex: 1;
		font-size: 26upx;
		color: #909399;
		position: relative;

		.zan-box {
			display: flex;
			align-items: base-line;
			position: absolute;
			top: 10upx;
			right: 10upx;

			.yticon {
				margin-left: 8upx;
			}
		}

		.content {
			font-size: 28upx;
			color: #333;
			padding-top: 20upx;
		}
	}

	/* 底部 */
	.bottom {
		flex-shrink: 0;
		display: flex;
		align-items: center;
		height: 90upx;
		padding: 0 30upx;
		box-shadow: 0 -1px 3px rgba(0, 0, 0, .04);
		position: relative;
		z-index: 1;

		.input-box {
			display: flex;
			align-items: center;
			flex: 1;
			height: 60upx;
			background: #f2f3f3;
			border-radius: 100px;
			padding-left: 30upx;

			.icon-huifu {
				font-size: 28upx;
				color: #909399;
			}

			.input {
				padding: 0 20upx;
				font-size: 28upx;
				color: #303133;
			}
		}

		.confirm-btn {
			font-size: 30upx;
			padding-left: 20upx;
			color: #0d9fff;
		}
	}
</style>
